<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图书-书评管理</title>
    <link rel="icon" href="/static/images/t_logo.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/lyk-global.css" />
    <link rel="stylesheet" href="/static/elementui/lib/theme-chalk/index.css">
    <script src="/static/js/jquery.min.js" type="text/javascript"></script>
    <script src="/static/js/requestApi.js" type="text/javascript"></script>
    <script src="/static/js/vue/vue.js"></script>
    <!-- 引入elementui -->
    <script src="/static/elementui/js/element.js"></script>
    <script src="/static/js/axios.min.js"></script>
    <script src="/static/js/axios-config.js"></script>
    <script src="/static/js/utilJs.js"></script>
</head>
<style>
    *{
        font-size: 14px
    }
    [v-cloak] {
        display: none;
    }
</style>
<body style="background-color: #fff">
<div id="app" v-cloak>
    <div class="mt-8 ml-4">
        <el-select size="small" v-model="queryParam.nameOrId">
            <el-option key="1" label="书籍名称" value="1"></el-option>
            <el-option key="2" label="idbn" value="2"></el-option>
        </el-select>
        <el-input placeholder="请输入搜索关键字" size="small" style="width:200px;" class="ml-2" v-model="queryParam.nameAndId" @keyup.native.enter="getTableDataMethod(true)"></el-input>
        <el-select size="small" v-model="queryParam.state" placeholder="请选择状态" @change="getTableDataMethod(true)">
            <el-option key="0" label="待审核" value="0"></el-option>
            <el-option key="1" label="审核通过" value="1"></el-option>
            <el-option key="2" label="审核不通过" value="2"></el-option>
        </el-select>
        <el-button type="primary" size="small" class="ml-2" @click="getTableDataMethod(true)">搜索</el-button>


        <el-table :data="tableData" v-loading="tableDataLoading" class="mt-4">
            <el-table-column prop="bookName" label="名称"></el-table-column>
            <el-table-column prop="picUrl" label="封面">
                <template slot-scope="scope">
                    <img :src="'/book/getLocalSystemPic?filePath=' + scope.row.picUrl" alt="Smiley face" width="42" height="42" v-if="scope.row.picUrl">
                </template>
            </el-table-column>
            <el-table-column prop="createUser" label="评论人"></el-table-column>
            <el-table-column prop="fullName" label="评论人全称"></el-table-column>
            <el-table-column prop="createTime" label="评论时间"></el-table-column>
            <el-table-column prop="content" label="评论内容"></el-table-column>
            <el-table-column label="状态">
                <template slot-scope="scope">
                    <el-tag type="info" class="ml-2" v-if="scope.row.state == 0">待审核</el-tag>
                    <el-tag type="success" class="ml-2" v-if="scope.row.state == 1">审核通过</el-tag>
                    <el-tag type="warning" class="ml-2" v-if="scope.row.state == 2">审核不通过</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-popconfirm title='是否审核通过该条数据？'
                                   @confirm="auditCommentMethod(scope.row,1)" v-if="scope.row.state == 0">
                        <span class="copy-a" slot="reference" >审核通过</span>
                    </el-popconfirm>

                    <el-popconfirm title='是否审核不通过该条数据？'
                                   @confirm="auditCommentMethod(scope.row,2)" v-if="scope.row.state == 0">
                        <span class="copy-a" slot="reference" >审核不通过</span>
                    </el-popconfirm>

                    <el-popconfirm title='是否删除该条数据？'
                                   @confirm="delCommentMethod(scope.row)">
                        <span class="copy-a" style="color:red !important;" slot="reference" >删除</span>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background layout="total,sizes,prev, pager, next" :total="tableDataPaging.total"
                       :page-sizes="[10, 20, 50]"
                       prev-text="上一页" next-text="下一页"
                       :page-size="tableDataPaging.pageSize"
                       :current-page="tableDataPaging.currentPage"
                       @current-change="tableDataPagingChange"
                       @prev-click="tableDataPagingChange" @next-click="tableDataPagingChange"
                       @size-change="tableDataPagingSizeChange"
                       style="float:right;margin-top: 40px;padding-bottom:50px;">
        </el-pagination>


    </div>

</div>
</body>

<script type="text/javascript">
    const vm = new Vue({ // 配置对象 options
        // 配置选项(option)
        el: '#app', // element: 指定用vue来管理页面中的哪个标签区域
        components: {
        },
        data() {
            return {
                currentLoginUserName:"",
                queryParam : {
                    nameOrId:"1",
                    nameAndId:"",
                    bookName:"",
                    typeId:"",
                    isbn:"",
                    ticketNumber:""
                },
                tableData : [],
                tableDataLoading : false,
                tableDataPaging : {
                    currentPage : 1,
                    pageSize : 10,
                    total : 0,
                },

            }
        },
        mounted() {
            let that = this;
            this.$nextTick(function () {
                that.currentLoginUserName = localStorage.getItem('userId');
                that.getTableDataMethod(true);
            });
        },
        methods: {
            tableDataPagingChange(val) {
                let that = this;
                that.tableDataPaging.currentPage = val;
                that.getTableDataMethod();
            },
            tableDataPagingSizeChange(val) {
                let that = this;
                that.tableDataPaging.pageSize = val;
                that.getTableDataMethod();
            },
            //获取表格的数据
            getTableDataMethod(isChongZhi){
                let that = this;
                if (isChongZhi) {
                    this.tableDataPaging.currentPage = 1;
                }
                const {bookName,isbn,ticketNumber,nameOrId,nameAndId,state} = this.queryParam
                let queryData = {
                    bookName: $.trim(bookName),
                    isbn: $.trim(isbn),
                    ticketNumber: $.trim(ticketNumber),
                    nameOrId: $.trim(nameOrId),
                    nameAndId: $.trim(nameAndId),
                    state: $.trim(state),
                    pageNum: this.tableDataPaging.currentPage,
                    pageSize: this.tableDataPaging.pageSize,
                }
                this.tableDataLoading = true;
                that.tableData = [];
                requestApiTB("comment/getCommentList",queryData,'post',function (res){
                    that.tableDataLoading = false;
                    if (res.code === 0) {
                        that.tableData = res.data.list;
                        that.tableDataPaging.total = res.data.total;
                    }else{
                        that.$message.error("error");
                    }
                });
            },

            //审核评论
            auditCommentMethod(row,state){
                let that = this;
                if(!row.id){
                    alert("请传递参数")
                    return;
                }
                requestApi("comment/auditComment",{id:row.id,"state":state},'post',function (res){
                    that.tableDataLoading = false;
                    if (res.code === 0) {
                        alert("操作成功");
                        that.getTableDataMethod(true);
                    }else{
                        alert(res.msg);
                    }
                });
            },

            //删除评论
            delCommentMethod(row){
                let that = this;
                if(!row.id){
                    alert("请传递参数")
                    return;
                }
                requestApi("comment/delComment",{id:row.id},'post',function (res){
                    that.tableDataLoading = false;
                    if (res.code === 0) {
                        alert("操作成功");
                        that.getTableDataMethod(true);
                    }else{
                        alert(res.msg);
                    }
                });
            },

        }
    })
</script>
</html>